<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <link class="theme" rel="stylesheet" type="text/css" href="./css/color/blue.css" />
    <script type="text/javascript" src="./script/doT.min.js"></script>

</head>

<body>
    <div class="head">
        <div class="head-s">
            <span><div id='topbar'>市管领导干部信息查询系统--自定义查询</div></span>
            <div class="head-r"><i class="fa fa-user-circle-o" onclick="user()"></i></div>
        </div>
    </div>

    <div class="header-d"></div>
    <form action="javascript:search();" method="get">
        <div id="list">
        </div>
        <script type='text/template' id='template'>
            <div id='textbox' class="search">
                <ul>
                    <li>
                        <p>分类：</p>
                        <select class="text-1" id='fenlei'>
                <option>全部</option>
                  <!-- {{~it :value:index}}
                  <option>{{=value.DName}}</option>
                  {{~}} -->
                  <option>省管干部</option>
                  <option>市管干部</option>
                  <option>&nbsp;&nbsp;&nbsp;&nbsp;市直部门</option>
                  <option>&nbsp;&nbsp;&nbsp;&nbsp;县(市)区</option>
                  <option>&nbsp;&nbsp;&nbsp;&nbsp;事业单位</option>
             </select>
                    </li>

                    <li>
                        <p>姓名：</p>
                        <input class="text-1" type="text" name="name">
                    </li>
                    <li>
                        <p>年龄：</p>
                        <input class="text-2" type="text" name='mixAge' placeholder="0">
                        <span>-</span>
                        <input class="text-2" type="text" name='maxAge' placeholder="100">
                    </li>
                    <li>
                        <p>性别：</p>
                        <div class="aui-list-item-input" name='sex'>
                            <label><input class="aui-radio" type="radio" value='全部' name="sex" checked>全部</label>
                            <label><input class="aui-radio" type="radio" value='男' name="sex">男</label>
                            <label><input class="aui-radio" type="radio" value='女' name="sex">女</label>
                    </li>
                    <li>
                        <p>现任职务：</p>
                        <input class="text-1" type="text" name='post'>
                    </li>
                    <li>
                        <p>是否为党员：</p>
                        <select class="text-1" id='partMember'>
              <option>全部</option>
                <option>是</option>
                <option>否</option>
            </select>
                    </li>
                    <li>
                        <p>全日制学历：</p>
                        <select class="text-1" id='allEducation'>
              <option>全部</option>
                <option>研究生</option>
                <option>大学及以上</option>
                <option>大学</option>
                <option>大专及以上</option>
                <option>大专</option>
                <option>中专及以上</option>
                <option>中专</option>
            </select>
                    </li>
                    <li>
                        <p>学历：</p>
                        <select class="text-1" id='education'>
              <option>全部</option>
                <option>研究生</option>
                <option>大学及以上</option>
                <option>大学</option>
                <option>大专及以上</option>
                <option>大专</option>
                <option>中专及以上</option>
                <option>中专</option>
            </select>
                    </li>
                    <li>
                        <p>学位：</p>
                        <select class="text-1" id='degree'>
                <option>全部</option>
                <option>博士</option>
                <option>硕士</option>
                <option>学士</option>
            </select>
                    </li>
                    <li>
                        <p>毕业院校及专业：</p>
                        <input class="text-1" type="text" name="full_time">
                    </li>
                    <li>
                        <p>任职状态：</p>
                        <select class="text-1" id='job'>
                <option selected>全部</option>
                <option>现职</option>
                <option>离岗退养</option>
                <option>享受政策</option>
            </select>
                    </li>

                </ul>
                <div class="search-btn">
                    <!-- <button type="button" onclick="search()">搜索</button> -->
                    <button type="Submit" />搜索</button>
                    <button type="button" onclick="chongzhi()">重置</button>
                </div>
                </div>
        </script>
        </from>
</body>
<script type="text/javascript" src="./script/api.js"></script>

</html>
<script>
    function chongzhi() {
        api.openFrame({
            name: 'searchnew',
            url: './searchnew.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                marginBottom: 70
            },
            reload: true
        });
    }

    function user() {
        api.openWin({
            name: 'user',
            url: './user.html',
        });
    }
    var sqlite;



    function search() {
        // sqlite =
        //     'SELECT * from ( SELECT a.ID as userID,a.I01,a.I02,a.I03,a.I04,a.I05,a.I06,a.I07,a.I08,a.I09,a.I10,a.I11,a.I12,a.I13,a.I14,a.I15,a.I24,a.I25,a.I16,a.I45,a.I46,a.I53,b.Ldr_id,b.isort as ldrisort,c.ID,c.isort as partisort, d.ID, d.PID as d,d.isort as leveisort from Base_Info as a join base_dptldr as b join (select min(id) as id,ldr_id from Base_DptLdr group by ldr_id) as x join Base_Depart as c join Base_Level as d WHERE b.Ldr_id =a.ID AND c.ID = b.Dpt_ID AND c.PID = d.ID and b.id=x.id ) as b inner join Base_level as a WHERE ';
        //
        // sql = 'a.ID = b.d '
//        var sql1 = 'SELECT * from ( SELECT a.ID as userID,a.I01,a.I02,a.I03,a.I04,a.I05,a.I06,a.I07,a.I08,a.I09,a.I10,a.I11,a.I12,a.I13,a.I14,a.I15,a.I24,a.I25,a.I16,a.I45,a.I46,a.I53,b.Ldr_id,b.isort as ldrisort,c.ID,c.isort as partisort, d.ID, d.PID as d,d.isort as leveisort,y.isort as leveisort0 from Base_Info as a join base_dptldr as b join (SELECT MIN(c.ID) AS ID, c.Ldr_ID  FROM Base_Depart d JOIN Base_DptLdr c ON d.ID = c.Dpt_ID JOIN Base_Level c1 ON d.PID = c1.ID JOIN (SELECT ID, Pid,dname, isort FROM Base_Level WHERE pid = 0) b ON c1.PID = b.ID  JOIN Base_Info a ON c.Ldr_ID = a.ID WHERE (1 = 1)  ';

//      var  sql2=  ' GROUP BY c.Ldr_ID) as x join Base_Depart as c join Base_Level as d join (select id,isort from base_level where pid="0") as y ';
//          sql2 = sql2 + ' WHERE b.Ldr_id =a.ID AND c.ID = b.Dpt_ID AND c.PID = d.ID and b.id=x.id and y.id=d.pid ) as b inner join Base_level as a WHERE a.ID = b.d  ';

var sql1='';
var sql2='';
var sql3='';
var tblname='';
         sql1='SELECT a.ID as userID,a.I01,a.I02,a.I03,a.I04,a.I05,a.I06,a.I07,a.I08,a.I09,a.I10,a.I11,a.I12,a.I13,a.I14,a.I15,a.I24,a.I25,a.I16,a.I45,a.I46,a.I53, ';
         sql1=sql1+'c.Ldr_id,c.isort as ldrisort,c.ID,c.isort as partisort, d.ID, d.isort as leveisort,c1.isort as leveisort0 ';
         sql1=sql1+'FROM Base_Depart d INNER JOIN ';
         sql1=sql1+'Base_DptLdr c ON d.ID = c.Dpt_ID INNER JOIN ';
         sql1=sql1+'Base_Level c1 ON d.PID = c1.ID INNER JOIN ';
         sql1=sql1+'(SELECT ID, Pid, dname, isort FROM Base_Level WHERE pid = 0) b ON c1.PID = b.ID INNER JOIN ';
         sql1=sql1+'Base_Info a ON c.Ldr_ID = a.ID INNER JOIN ';
         sql1=sql1+'(SELECT MIN(c.ID) AS ID, c.Ldr_ID FROM Base_Depart d INNER JOIN ';
         sql1=sql1+'Base_DptLdr c ON d .ID = c.Dpt_ID INNER JOIN ';
         sql1=sql1+'Base_Level c1 ON d .PID = c1.ID INNER JOIN ';
         sql1=sql1+'(SELECT ID, Pid, dname, isort FROM Base_Level WHERE pid = 0) b ON c1.PID = b.ID ';
         sql1=sql1+'inner JOIN Base_Info a ON c.Ldr_ID = a.ID ';
         sql1=sql1+'WHERE (1 = 1) ';
         sql2=' GROUP BY c.Ldr_ID) x ON c.ID = x.ID WHERE (1 = 1) ';
         sql3=' ORDER BY b.isort, c1.isort, ifnull(d.iSort, d.ID), c.iSort ';

        var sql='';
        var fenlei = $('#fenlei').val();
        if (fenlei != '全部') {
          if (fenlei=='市管干部') {
            fenlei = "'" + fenlei + "'";
            sql = sql + ' AND  b.DName != "省管干部"';

          }else {
            fenlei = "'" + fenlei + "'";
            sql = sql + ' AND  b.DName=' + fenlei;
          }

        }
        var name = $('input[name="name"]').val();
        if (name != '') {
            name = "'%" + name + "%'";
            nameSql = ' AND I01 LIKE' + name;
            sql = sql + nameSql;
        }
        //年龄
        var mixAge = $('input[name="mixAge"]').val();
        var maxAge = $('input[name="maxAge"]').val();
        if (mixAge == '') {
            mixAge = 0;
        }
        if (maxAge == '') {
            maxAge = 100;
        }

        sql=  sql + ' AND '+ mixAge+ ' <= substr((julianday(date())-julianday(i03))/365.25,1,2)*1  AND ' + ' substr((julianday(date())-julianday(i03))/365.25,1,2)*1 <= '  + maxAge;


        //性别
        var sex = $('input:radio[name="sex"]:checked').val();
        if (sex != '全部') {
            sex = "'" + sex + "'";
            sql = sql + ' AND I02 = ' + sex;
        }

        // 现任职务
        var post = $('input[name="post"]').val();
        if (post != '') {
            post = "'%" + post + "%'";
            sql = sql + ' AND ' + "I16 LIKE " + post
        }

        var allEducation = $('#allEducation').val();
            if (allEducation != '全部') {
              if (allEducation == '中专及以上') {
                  //  sql = sql + ' AND ( I12 LIKE "%大专%"  OR  I12 LIKE "%大学%"  OR  I12 LIKE "%研究生%"  OR  I14 LIKE "%大专%"  OR  I14 LIKE "%大学%" OR   I14 LIKE "%研究生%" )';
              } else if (allEducation == '大专及以上') {
                  sql = sql + ' AND ( I12 LIKE "%大专%"  OR  I12 LIKE "%大学%"  OR  I12 LIKE "%研究生%")';
              } else if (allEducation == '大学及以上') {
                  sql = sql + ' AND (  I12 LIKE "%大学%"  OR  I12 LIKE "%研究生%" )';
              } else {
                  allEducation = "'%" + allEducation + "%'";
                  sql = sql + ' AND ( I12 LIKE ' + allEducation + ' OR I12 LIKE "中技" )';
              }

            }
        //学历
        var education = $('#education').val();
        if (education != '全部') {
            if (education == '中专及以上') {
                //  sql = sql + ' AND ( I12 LIKE "%大专%"  OR  I12 LIKE "%大学%"  OR  I12 LIKE "%研究生%"  OR  I14 LIKE "%大专%"  OR  I14 LIKE "%大学%" OR   I14 LIKE "%研究生%" )';
            } else if (education == '大专及以上') {
                sql = sql + ' AND ( I12 LIKE "%大专%"  OR  I12 LIKE "%大学%"  OR  I12 LIKE "%研究生%"  OR  I14 LIKE "%大专%"  OR  I14 LIKE "%大学%" OR   I14 LIKE "%研究生%" )';
            } else if (education == '大学及以上') {
                sql = sql + ' AND (  I12 LIKE "%大学%"  OR  I12 LIKE "%研究生%" OR  I14 LIKE "%大学%" OR   I14 LIKE "%研究生%" )';
            } else {
                education = "'%" + education + "%'";
                sql = sql + ' AND ( I12 LIKE ' + education + ' OR  I12 LIKE "中技" OR I14 LIKE ' + education + ' OR  I14 LIKE "中技" )';
            }
        }
        //全日制学历
        var degree = $('#degree').val();
        if (degree != '全部') {
            degree = "'%" + degree + "%'";
            sql = sql + ' AND ( I12 LIKE ' + degree + ' OR  I14 LIKE ' + degree + ' )';
        }
        var job = $('#job').val();
        if (job != '全部') {
            job = "'%" + job + "%'";
            sql = sql + ' AND ' + "I45 LIKE " + job
        }
        var full_time = $('input[name="full_time"]').val();
        if (full_time != '') {
            full_time = "'%" + full_time + "%'";

            // sql = sql + ' AND I13 LIKE ' + full_time + ' OR ' + sql + ' AND I15 LIKE ' + full_time;
            sql = sql + ' AND (I13 LIKE ' + full_time + ' OR I15 LIKE' + full_time + ')';
        }
        //党员
        var partMember = $('#partMember').val();
        if (partMember == '全部') {
            partMember = 0;
        } else if (partMember == '是') {
            partMember = 1;
        } else {
            partMember = 2;
        }

        var tempsql = sql1 + sql +sql2 +sql+ sql3;
        // console.log(tempsql);
        api.showProgress({
            title: '努力加载中...',
            modal: false
        });
        api.openFrame({
            name: 'fanansearch',
            url: './fanansearch.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                marginBottom: 60
            },
            reload: true,
            pageParam: {
                sql: tempsql,
                d: partMember,
                title: '市管领导干部信息查询系统--自定义查询'
            },
            bounces: false,
            bgColor: 'rgba(0,0,0,0)',
            vScrollBarEnabled: true,
            hScrollBarEnabled: true
        });

        // api.showProgress({
        //     title: '努力加载中...',
        //     // text: '先喝杯茶...',
        //     modal: false
        // });
    }

    apiready = function() {
        var color = $api.getStorage('color');
        $(".theme").attr("href", color);

        var tempId;
        var db = api.require('CPDB');
        db.selectSql({
            name: 'data',
            sql: "SELECT * FROM base_level WHERE PID = 0 ORDER BY isort"
        }, function(ret, err) {
            if (ret.status) {
                tempId = ret.data[0].ID;
                title = ret.data;
                var dotFn = doT.template(template.innerHTML);
                var html = dotFn(ret.data);
                var list = $api.byId('list');
                $api.html(list, html);
                //分类
                $('#I0').addClass('active');
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    function changeColor() {
        var color = $api.getStorage('color');
        $(".theme").attr("href", color);
    }

    function getcurrent(age) {
        //将一个月的日期填入搜索框
        var currentYear = new Date().getFullYear() - age;
         var current = currentYear + "-01-01";
        // var currentMonth = new Date().getMonth() + 1;
        // var currentDate = new Date().getDate();
        // var current = currentYear + "-" + currentMonth + "-" + p(currentDate);
        return current;
    }

    function p(s) {
        return s < 10 ? '0' + s : s;
    }
</script>
